package com.eonmind.ai.mapper;

import com.eonmind.common.contract.data.base.BaseMongoMapper;
import com.eonmind.common.contract.enums.DelEnum;
import com.eonmind.common.contract.enums.StatusEnum;
import com.eonmind.common.provider.entity.ai.AiModel;
import com.mongoplus.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AiModelMapper extends BaseMongoMapper<AiModel> {


    public List<AiModel> selectByStatus(Integer code) {
        QueryWrapper<AiModel> eq = createMgoQuery().eq(AiModel::getModelStatus, code)
                .eq(AiModel::getDel, DelEnum.UN_DEL.getCode());
        return list(eq);
    }

    public AiModel getValidModelById(Long modelId) {
        QueryWrapper<AiModel> eq = createMgoQuery().eq(AiModel::getId, modelId)
                .eq(AiModel::getModelStatus, StatusEnum.OPENED.getCode())
                .eq(AiModel::getDel, DelEnum.UN_DEL.getCode());
        return one(eq);
    }

    public List<AiModel> selectByIds(List<Long> modelIdList) {
        QueryWrapper<AiModel> eq = createMgoQuery()
                .in(AiModel::getId, modelIdList)
                .eq(AiModel::getModelStatus, StatusEnum.OPENED.getCode())
                .eq(AiModel::getDel, DelEnum.UN_DEL.getCode());
        return list(eq);
    }

    public List<AiModel> selectByKeyword(String keyword) {
        QueryWrapper<AiModel> eq = createMgoQuery()
                .like(StringUtils.isNoneBlank(keyword), AiModel::getModelName, keyword)
                .eq(AiModel::getDel, DelEnum.UN_DEL.getCode())
                .eq(AiModel::getModelStatus, StatusEnum.OPENED.getCode());
        return list(eq);
    }
}
